package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.NursingLevel;
import com.zzyl.nursing.service.INursingLevelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理等级Controller
 *
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/nursing/level" )
@Tag(name = "护理等级相关接口" )
public class NursingLevelController extends BaseController {
    @Autowired
    private INursingLevelService nursingLevelService;

    /**
     * 查询护理等级列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:level:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询护理等级列表" )
    public TableDataInfo list(NursingLevel nursingLevel) {
        startPage();
        List<NursingLevel> list = nursingLevelService.selectNursingLevelList(nursingLevel);
        return getDataTable(list);
    }

    /**
     * 导出护理等级列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:level:export')" )
    @Log(title = "护理等级" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出护理等级列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, NursingLevel nursingLevel) {
        List<NursingLevel> list = nursingLevelService.selectNursingLevelList(nursingLevel);
        ExcelUtil<NursingLevel> util = new ExcelUtil<NursingLevel>(NursingLevel.class);
        util.exportExcel(response, list, "护理等级数据" );
    }

    /**
     * 获取护理等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:level:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取护理等级详细信息" )
    public R<NursingLevel> getInfo(@Schema(title = "护理等级ID" )
                                   @PathVariable("id" ) Long id) {
        return R.ok(nursingLevelService.selectNursingLevelById(id));
    }

    /**
     * 新增护理等级
     */
    @PreAuthorize("@ss.hasPermi('nursing:level:add')" )
    @Log(title = "护理等级" , businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增护理等级" )
    public AjaxResult add(@Schema(title = "护理等级实体" ) @RequestBody NursingLevel nursingLevel) {
        return toAjax(nursingLevelService.insertNursingLevel(nursingLevel));
    }

    /**
     * 修改护理等级
     */
    @PreAuthorize("@ss.hasPermi('nursing:level:edit')" )
    @Log(title = "护理等级" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改护理等级" )
    public AjaxResult edit(@Schema(title = "护理等级实体" ) @RequestBody NursingLevel nursingLevel) {
        return toAjax(nursingLevelService.updateNursingLevel(nursingLevel));
    }

    /**
     * 删除护理等级
     */
    @PreAuthorize("@ss.hasPermi('nursing:level:remove')" )
    @Log(title = "护理等级" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除护理等级" )
    public AjaxResult remove(@Schema(title = "护理等级ID数组" ) @PathVariable Long[] ids) {
        return toAjax(nursingLevelService.deleteNursingLevelByIds(ids));
    }

    /**
     * 查询所有护理等级
     */
    @GetMapping("/all" )
    public AjaxResult allLevel() {
        return success(nursingLevelService.list());
    }
}
